<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- topic.qdoc -->
  <title>Integrating QML and JavaScript | Qt QML 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtqml-index.html">Qt QML</a></td><td >Integrating QML and JavaScript</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtqml-index.html">Qt 
5.12.3 <span lang="zh-cn">参考指南</span></a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><span lang="zh-cn">目录</span></h3>
<ul>
<li class="level1"><a href="#javascript-expressions">JavaScript
<span lang="zh-cn">表达式</span></a></li>
<li class="level1"><a href="#javascript-resources">JavaScript <span lang="zh-cn">
资源</span></a></li>
<li class="level1"><a href="#javascript-imports">JavaScript <span lang="zh-cn">
导入</span></a></li>
<li class="level1"><a href="#javascript-host-environment">JavaScript
<span lang="zh-cn">主机环境</span></a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title"><span lang="zh-cn">集成</span>QML<span lang="zh-cn">和</span>JavaScript</h1>
<span class="subtitle"></span>
<!-- $$$qtqml-javascript-topic.html-description -->
<div class="descr"> <a name="details"></a>
<p>QML语言使用类似json的语法，并允许将各种表达式和方法定义为JavaScript函数。<br>
它还允许用户导入JavaScript文件并使用这些导入提供的功能。</p>
<p>这允许开发人员和设计人员利用他们所掌握的JavaScript知识来快速开发用户界面和应用程序逻辑。</p>
<a name="javascript-expressions"></a>
<h2 id="javascript-expressions">JavaScript <span lang="zh-cn">表达式</span></h2>
<p>QML支持高度集成JavaScript，并允许在JavaScript中定义<a href="qtqml-syntax-objectattributes.html#signal-attributes">信号处理程序</a>和<a href="qtqml-syntax-objectattributes.html#method-attributes">方法</a>。QML的另一个核心特性是使用<a href="qtqml-syntax-propertybinding.html">property 
属性绑定</a>指定和加强对象属性之间的关系的能力，属性绑定也是使用JavaScript定义的。</p>
<p>有关在QML中使用JavaScript表达式的更多信息，请参阅文档页标题为“<a href="qtqml-javascript-expressions.html">QML文档中的JavaScript表达式</a>”。</p>
<a name="javascript-resources"></a>
<h2 id="javascript-resources">JavaScript<span lang="zh-cn"> 资源</span></h2>
<p>
在JavaScript函数中定义的应用程序逻辑可以被分离到单独的JavaScript文件中，这些文件称为JavaScript资源。有几种不同类型的JavaScript资源，它们具有不同的语义。</p>
<p>有关为QML定义JavaScript资源的更多信息，请参阅文档中标题为<a href="qtqml-javascript-resources.html">Defini<span lang="zh-cn">在QML中定义JavaScript资源</span></a>的页面。</p>
<a name="javascript-imports"></a>
<h2 id="javascript-imports">JavaScript <span lang="zh-cn">导入</span></h2>
<p>QML文档可以导入JavaScript资源，而JavaScript资源可以导入其他JavaScript资源以及QML模块。<br>
这允许应用程序开发人员以模块化的、自包含的文件提供应用程序逻辑。</p>
<p>See the documentation page titled&nbsp; for more information on how to import JavaScript resources and how to use the functionality they provide.有关如何导入JavaScript资源以及如何使用它们提供的功能的更多信息，请参阅文档页面<a href="qtqml-javascript-imports.html">导入JavaScript资源</a>。</p>
<a name="javascript-host-environment"></a>
<h2 id="javascript-host-environment">JavaScript<span lang="zh-cn">主机环境</span></h2>
<p>QML引擎提供的JavaScript环境与web浏览器提供的JavaScript环境有一些不同。<br>
某些限制适用于在环境中运行的代码，并且QML引擎在根上下文中提供了JavaScript开发人员可能不熟悉的各种对象。</p>
<p>These limitations and extensions are documented in the description of the&nbsp; provided by the QML engine.这些限制和扩展记录在由QML引擎提供的<a href="qtqml-javascript-hostenvironment.html">JavaScript主机环境</a>描述中。</p>
</div>
<!-- @@@qtqml-javascript-topic.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
